import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
import { useStore } from "vuex";

const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    redirect: "/user",
    meta: {
      whitelist: true,
    },
  },
  {
    path: "/user",
    name: "user",
    meta: {
      whitelist: true,
    },
    redirect: "/user/login?from=user",
    component: () => import("../views/user/index.vue"),
    children: [
      {
        path: "login",
        name: "Login",
        component: () => import("../views/user/login.vue"),
        meta: {
          whitelist: true,
        },
      },
      {
        path: "register",
        name: "register",
        component: () => import("../views/user/register.vue"),
        meta: {
          whitelist: true,
        },
      },
    ],
  },
  {
    path: "/admin/login",
    redirect: "/user/login?from=admin",
    meta: {
      whitelist: true,
    },
  },
  {
    path: "/app",
    name: "app",
    component: () => import("../views/app/index.vue"),
    children: [
      {
        path: "ydgl",
        name: "ydgl",
        component: () => import("../views/app/ydgl.vue"),
      },
      {
        path: "fjgl",
        name: "fjgl",
        component: () => import("../views/app/fjgl.vue"),
      },
      {
        path: "fjlx",
        name: "fjlx",
        component: () => import("../views/app/fjlx.vue"),
      },
      {
        path: "fjlc",
        name: "fjlc",
        component: () => import("../views/app/fjlc.vue"),
      },
      {
        path: "bqgl",
        name: "bqgl",
        component: () => import("../views/app/bqgl.vue"),
      },
      {
        path: "yjgl",
        name: "yjgl",
        component: () => import("../views/app/yjgl.vue"),
      },
      {
        path: "dtzk",
        name: "dtzk",
        component: () => import("../views/app/dtzk.vue"),
      },
      {
        path: "tcgl",
        name: "tcgl",
        component: () => import("../views/app/tcgl.vue"),
      },
      {
        path: "yhgl",
        name: "yhgl",
        component: () => import("../views/app/yhgl.vue"),
      },
      {
        path: "yggl",
        name: "yggl",
        component: () => import("../views/app/yggl.vue"),
      },
      {
        path: "rzdj",
        name: "rzdj",
        component: () => import("../views/app/rzdj.vue"),
      },
      {
        path: "spgl",
        name: "spgl",
        component: () => import("../views/app/spgl.vue"),
      },
      {
        path: "gysgl",
        name: "gysgl",
        component: () => import("../views/app/gysgl.vue"),
      },
      {
        path: "vipgl",
        name: "vipgl",
        component: () => import("../views/app/vipgl.vue"),
      },
      {
        path: "vippp",
        name: "vippp",
        component: () => import("../views/app/vippp.vue"),
      },
      {
        path: "rzgl",
        name: "rzgl",
        component: () => import("../views/app/rzgl.vue"),
      },
      {
        path: "lsck",
        name: "lsck",
        component: () => import("../views/app/lsck.vue"),
      },
    ],
  },
  {
    path: "/about",
    name: "About",
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/About.vue"),
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});
router.beforeEach((to, from, next) => {
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  // @ts-ignore
  to.meta.whitelist || window["user"].username
    ? next()
    : next({ name: "Login" });
});

export default router;
